var t = getApp(),
  a = t.requirejs("core");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    star_time: '',
    end_time: '',
    bq_id: 0,
    status: 1,
    array: ['今天', '本周', '本月', '今年', '全部'],
    index: 0,
    time: 'd',
  },

  /**
   * 生命周期函数--监听页面加载e
   */
  onLoad: function (options) {
    this.setData(options)
    this.count()
  },
  count: function () {
    var that = this,
      star_time = that.data.star_time,
      end_time = that.data.end_time;
    a.get('Shop/data_count', {
      star_time: star_time,
      end_time: end_time,
      time: that.data.time,
      shop_id: that.data.shop_id
    }, function (t) {
      if (t.code == 0) {
        that.setData({
          show: true,
          info: t.info
        })
      }else{
        a.alert(t.msg);
      }
    }, true)
  },
  selecttime: function (e) {
    var data = a.pdata(e).status;
    var status = data == 2 ? 1 : 2;
    this.setData({
      status: status
    });
  },
  bindPickerChange: function (e) {
    var time = '',
      i = e.detail.value;
    if (i == 0) {
      time = 'd';
    }else if (i == 1) {
      time = 'w';
    } else if (i == 2) {
      time = 'm';
    } else if (i == 3) {
      time = 'y';
    }
    this.setData({
      time: time,
      index: i,
      star_time: '',
      end_time: '',
      status: 1,
    });
    this.count();
  },
  select: function (e) {
    var time = a.pdata(e).time;
    this.setData({
      time: time,
      star_time: '',
      end_time: '',
      status: 1
    });
    this.count();
  },
  /**
 * 监听开始时间
 */
  listenerStarTime: function (e) {
    //调用setData()重新绘制
    this.setData({
      star_time: e.detail.value,
    });
  },
  /**
  * 监听结束时间
  */
  listenerEndTime: function (e) {
    //调用setData()重新绘制
    this.setData({
      end_time: e.detail.value,
    });
  },
  /**
 * 监听bq_id
 */
  listenerBqid: function (e) {
    console.log(e)
    var that = this,
      bq_index = e.detail.value;
    that.data.nurselist.forEach(function (t, k) {
      if (k == bq_index) {
        that.setData({
          bq_index: bq_index,
          bq_id: t.id
        })
      }
    })
    this.count()
  },
  serach: function () {
    var that = this,
      star_time = that.data.star_time,
      end_time = that.data.end_time;
    if (star_time == '' && end_time != '') {
      a.alert('请选择开始日期');
      return;
    } else if (star_time != '' && end_time == '') {
      a.alert('请选择结束日期');
      return;
    }
    else if (star_time != '' && end_time != '') {
      if (a.time_str(star_time) > a.time_str(end_time)) {
        a.alert('结束日期不小于开始日期');
        return;
      }
    }
    that.setData({
      time: ""
    })
    that.count()
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },



  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.count()
    wx.stopPullDownRefresh();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})